package com.wxq.yaoxia.mainborad;

import android.app.SearchManager;
import android.content.Intent;
import android.database.Cursor;
import android.util.Log;

import com.wxq.yaoxia.YXBaseSearchResultActivity;
import com.wxq.yaoxia.disease.YXDiseaseDetail;
import com.wxq.yaoxia.drug.YXDrugDetailActivity;
import com.wxq.yaoxia.util.YXConstants;


public class YXMainBoradResultActivity extends YXBaseSearchResultActivity {

	@Override
	public void setLVItemClickAction(int position) {
		// 选中某项的动作
		cursor.moveToPosition(position);
		Intent newIntent = new Intent();
		newIntent.putExtra(YXConstants.KEY_ID, cursor.getLong(cursor.getColumnIndex(YXConstants.KEY_ID)));
		newIntent.putExtra(YXConstants.COLUMN_Name, cursor.getString(cursor.getColumnIndex(YXConstants.COLUMN_Name)));
		newIntent.putExtra(YXConstants.DRUG_COLUMN_BrandName, cursor.getString(cursor.getColumnIndex(YXConstants.DRUG_COLUMN_BrandName)));
		newIntent.putExtra(YXConstants.DRUG_COLUMN_CommonName, cursor.getString(cursor.getColumnIndex(YXConstants.DRUG_COLUMN_CommonName)));
		newIntent.putExtra(YXConstants.COLUMN_QueryId, cursor.getString(cursor.getColumnIndex(YXConstants.COLUMN_QueryId)));
		if(YXConstants.YX_USE_DISEASE.equals(cursor.getString(cursor.getColumnIndex(YXConstants.DRUG_COLUMN_BrandName))))
		{
			newIntent.setClass(YXMainBoradResultActivity.this, YXDiseaseDetail.class);
		}
		else {
			newIntent.setClass(YXMainBoradResultActivity.this, YXDrugDetailActivity.class);
		}
		
		startActivity(newIntent);
	}

	@Override
	public Cursor getDoSearchCursor(String queryString) {
		// 点击搜索按钮的数据
		return dbHelper.getBothWithName(queryString);
	}

	@Override
	public Cursor getDoDefaultCursor(String queryString) {
		// 不含任何动作信息的数据，用不到
		return null;
	}

	@Override
	public Cursor getCheckData(String queryString) {
		// View数据，点击建议的数据
		Intent intent = getIntent();
		String queryId = intent.getStringExtra(SearchManager.EXTRA_DATA_KEY);
		Log.d("wxq", "queryString="+queryString+",id = "+queryId);
		if(YXConstants.YX_USE_DRUG.equals(queryString))
		{
			cursor = dbHelper.getDrugWithID(queryId);
		}
		else if (YXConstants.YX_USE_DISEASE.equals(queryString)) {
			cursor = dbHelper.getBothWithDiseaseID(queryId);
		}
		
		return cursor;
	}

	
}
